package cn.saltice.idempotence.testM.observer;

import lombok.extern.slf4j.Slf4j;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component;

/**
 * @program: idempotence
 * @description:
 * @author: Mr.Liu
 * @create: 2020-10-11 09:00
 **/
@Slf4j
@Component
public class Listening implements ApplicationListener<MyEvent> {
    @Override
    public void onApplicationEvent(MyEvent myEvent) {
        log.info("Listening："+myEvent.getMessage());
    }

    /**
     * 注解的方式，可以添加条件判断
     * @param e
     */
    @EventListener(condition = "#e.message.length()>4")
    public void myEventL(MyEvent e){
        log.info("Listening Annotation："+e.getMessage());
    }
}
